/**
 * 实施管理 API
 */

import { get, post, put, del } from '@/utils/request'

// ==================== 实施人员管理 ====================

/**
 * 获取实施人员列表
 */
export function getPersonnelList(params) {
  return get('/api/implementation/personnel', params)
}

/**
 * 获取实施人员详情
 */
export function getPersonnelDetail(id) {
  return get(`/api/implementation/personnel/${id}`)
}

/**
 * 新增实施人员
 */
export function addPersonnel(data) {
  return post('/api/implementation/personnel', data)
}

/**
 * 更新实施人员
 */
export function updatePersonnel(id, data) {
  return put(`/api/implementation/personnel/${id}`, data)
}

/**
 * 删除实施人员
 */
export function deletePersonnel(id) {
  return del(`/api/implementation/personnel/${id}`)
}

// ==================== 实施项目管理 ====================

/**
 * 获取实施项目列表
 */
export function getProjectList(params) {
  return get('/api/implementation/projects', params)
}

/**
 * 获取实施项目详情
 */
export function getProjectDetail(id) {
  return get(`/api/implementation/projects/${id}`)
}

/**
 * 新增实施项目
 */
export function addProject(data) {
  return post('/api/implementation/projects', data)
}

/**
 * 更新实施项目
 */
export function updateProject(id, data) {
  return put(`/api/implementation/projects/${id}`, data)
}

/**
 * 删除实施项目
 */
export function deleteProject(id) {
  return del(`/api/implementation/projects/${id}`)
}

/**
 * 获取项目团队成员
 */
export function getProjectTeam(projectId) {
  return get(`/api/implementation/projects/${projectId}/team`)
}

/**
 * 添加团队成员
 */
export function addTeamMember(projectId, data) {
  return post(`/api/implementation/projects/${projectId}/team`, data)
}

/**
 * 移除团队成员
 */
export function removeTeamMember(projectId, memberId) {
  return del(`/api/implementation/projects/${projectId}/team/${memberId}`)
}

// ==================== 实施任务管理 ====================

/**
 * 获取实施任务列表
 */
export function getTaskList(params) {
  return get('/api/implementation/tasks', params)
}

/**
 * 获取实施任务详情
 */
export function getTaskDetail(id) {
  return get(`/api/implementation/tasks/${id}`)
}

/**
 * 新增实施任务
 */
export function addTask(data) {
  return post('/api/implementation/tasks', data)
}

/**
 * 更新实施任务
 */
export function updateTask(id, data) {
  return put(`/api/implementation/tasks/${id}`, data)
}

/**
 * 删除实施任务
 */
export function deleteTask(id) {
  return del(`/api/implementation/tasks/${id}`)
}

/**
 * 更新任务状态
 */
export function updateTaskStatus(id, status) {
  return put(`/api/implementation/tasks/${id}/status`, { status })
}

/**
 * 更新任务进度
 */
export function updateTaskProgress(id, progress) {
  return put(`/api/implementation/tasks/${id}/progress`, { progress })
}

// ==================== 实施进度跟踪 ====================

/**
 * 获取项目进度
 */
export function getProjectProgress(projectId) {
  return get(`/api/implementation/progress/${projectId}`)
}

/**
 * 获取项目阶段列表
 */
export function getProjectPhases(projectId) {
  return get(`/api/implementation/progress/${projectId}/phases`)
}

/**
 * 更新阶段进度
 */
export function updatePhaseProgress(phaseId, progress) {
  return put(`/api/implementation/progress/phases/${phaseId}`, { progress })
}

/**
 * 获取里程碑列表
 */
export function getMilestones(projectId) {
  return get(`/api/implementation/progress/${projectId}/milestones`)
}

/**
 * 完成里程碑
 */
export function completeMilestone(milestoneId) {
  return post(`/api/implementation/progress/milestones/${milestoneId}/complete`)
}

// ==================== 客户反馈管理 ====================

/**
 * 获取客户反馈列表
 */
export function getFeedbackList(params) {
  return get('/api/implementation/feedback', params)
}

/**
 * 获取客户反馈详情
 */
export function getFeedbackDetail(id) {
  return get(`/api/implementation/feedback/${id}`)
}

/**
 * 新增客户反馈
 */
export function addFeedback(data) {
  return post('/api/implementation/feedback', data)
}

/**
 * 处理客户反馈
 */
export function processFeedback(id, data) {
  return post(`/api/implementation/feedback/${id}/process`, data)
}

/**
 * 回复客户反馈
 */
export function replyFeedback(id, data) {
  return post(`/api/implementation/feedback/${id}/reply`, data)
}

/**
 * 关闭客户反馈
 */
export function closeFeedback(id) {
  return post(`/api/implementation/feedback/${id}/close`)
}

// ==================== 实施知识库 ====================

/**
 * 获取知识文档列表
 */
export function getKnowledgeList(params) {
  return get('/api/implementation/knowledge', params)
}

/**
 * 获取知识文档详情
 */
export function getKnowledgeDetail(id) {
  return get(`/api/implementation/knowledge/${id}`)
}

/**
 * 新增知识文档
 */
export function addKnowledge(data) {
  return post('/api/implementation/knowledge', data)
}

/**
 * 更新知识文档
 */
export function updateKnowledge(id, data) {
  return put(`/api/implementation/knowledge/${id}`, data)
}

/**
 * 删除知识文档
 */
export function deleteKnowledge(id) {
  return del(`/api/implementation/knowledge/${id}`)
}

/**
 * 下载知识文档
 */
export function downloadKnowledge(id) {
  return get(`/api/implementation/knowledge/${id}/download`, {}, {
    responseType: 'blob'
  })
}

/**
 * 搜索知识文档
 */
export function searchKnowledge(keyword) {
  return get('/api/implementation/knowledge/search', { keyword })
}

// ==================== 统计分析 ====================

/**
 * 获取实施统计数据
 */
export function getImplementationStatistics() {
  return get('/api/implementation/statistics')
}

/**
 * 获取人员工作量统计
 */
export function getPersonnelWorkload(params) {
  return get('/api/implementation/statistics/workload', params)
}

/**
 * 获取项目统计报表
 */
export function getProjectStatistics(params) {
  return get('/api/implementation/statistics/projects', params)
}

/**
 * 获取客户满意度统计
 */
export function getSatisfactionStatistics(params) {
  return get('/api/implementation/statistics/satisfaction', params)
}

export default {
  // 人员
  getPersonnelList,
  getPersonnelDetail,
  addPersonnel,
  updatePersonnel,
  deletePersonnel,
  // 项目
  getProjectList,
  getProjectDetail,
  addProject,
  updateProject,
  deleteProject,
  getProjectTeam,
  addTeamMember,
  removeTeamMember,
  // 任务
  getTaskList,
  getTaskDetail,
  addTask,
  updateTask,
  deleteTask,
  updateTaskStatus,
  updateTaskProgress,
  // 进度
  getProjectProgress,
  getProjectPhases,
  updatePhaseProgress,
  getMilestones,
  completeMilestone,
  // 反馈
  getFeedbackList,
  getFeedbackDetail,
  addFeedback,
  processFeedback,
  replyFeedback,
  closeFeedback,
  // 知识库
  getKnowledgeList,
  getKnowledgeDetail,
  addKnowledge,
  updateKnowledge,
  deleteKnowledge,
  downloadKnowledge,
  searchKnowledge,
  // 统计
  getImplementationStatistics,
  getPersonnelWorkload,
  getProjectStatistics,
  getSatisfactionStatistics
}

